var api = require('../../../../api.js');

var utils = require('../../../../utils.js');
var WxParse = require('../../../../wxParse/wxParse.js');
var app = getApp();

// pages/integral/shoplist/shoplist.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        winWidth: 0,
        winHeight: 0,
        // tab切换  
        currentTab: 0,
        search_int: true,

    },
    // 分类 搜索
    search: function (e) {
        console.log(e.detail.value)
        var that = this;
        that.setData({
            int_val: e.detail.value
        })
        app.request({
            url: api.integralmall.commodity_search,
            data: {
                search: e.detail.value,
                
            },
            header: {},
            method: 'GET',
            dataType: 'json',
            responseType: 'text',
            success: function(res) {
                console.log(res)
                that.setData({
                    list:res
                })
            },
            fail: function(res) {},
            complete: function(res) {},
        })
    },
    // 弹出详情 弹框
    detail: function (e) {
        var that = this
        var cat_id = e.currentTarget.dataset.cat_id - 1
        var id_index = e.currentTarget.dataset.indexs
        var id = that.data._data[cat_id].goods[id_index].id
        var u_jf = that.data.u_jf
        console.log(cat_id + "cat_id")
        console.log(id_index + "id_index")
        console.log(id + "id")


        // return false;
        wx.navigateTo({
            url: '/pages/integral/shopdetail/shopdetail?id=' + id + '&u_jf=' + u_jf,
            success: function (res) { },
            fail: function (res) { },
            complete: function (res) { },
        })
    },
    // 搜索框 显示隐藏
    searchshow: function () {
        var that = this
        that.setData({
            search_int: !that.data.search_int
        })
    },
    onLoad: function (options) {
        console.log(options)
        var listid = options.id - 1;
        // var curremt_id = options.id;

        var that = this
        // that.setData({
        //     curremt_id: curremt_id
        // })
        //   禾匠 積分商城 data
        app.request({
            url: api.integralmall.index,
            data: '',
            header: {},
            method: 'GET',
            dataType: 'json',
            responseType: 'text',
            success: function (res) {
                console.log(res.data)
                console.log("========shoplist=======")
                that.setData({
                    _data: res.data.goods_list,
                    _shoplist: res.data,
                    u_jf: res.data.user.integral
                    //   _title: res.data.goods_list[listid].name
                })

            },
            fail: function (res) { },
            complete: function (res) { },
        })

   
    },
    // 点击 查看 点击的数据
    bindshoplist: function (e) {
        var that = this
        that.setData({
            curremt_id: e.target.dataset.id,
        })
    },
    // 滑动的时候
    swshoplist: function (e) {
        var that = this
        that.setData({
            curremt_id: e.detail.current
        })
    },


    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {


    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})